package echecs;

public abstract class ActionUtile extends Etat {

    private Predicat pPredicat1;
    private Predicat pPredicat2;
    private Action pFermeture1;
    private Action pFermeture2;
    private Action PieceDepart = new Action() {

        @Override
        public void exec() {
            pPieceDepart = PIECES[pIndexDepart];
        }
    };
    ActionUtile PourChaquePiece = new While(NouvelleCase, PieceDepart);

    public ActionUtile() {
    }



    public ActionUtile(Predicat pPredicat1, Action pFermeture1) {
        this.pPredicat1 = pPredicat1;
        this.pFermeture1 = pFermeture1;
    }

   public abstract void exec();

    public class While extends ActionUtile {

        public While(Predicat pPredicat1, Action pFermeture1) {
            super(pPredicat1, pFermeture1);
        }

        @Override
        public void exec() {
            while (pPredicat1.eval()) {
                pFermeture1.exec();
            }
        }
    }

    public class If extends ActionUtile {

        public If(Predicat pPredicat1, Action pFermeture1) {
            super(pPredicat1, pFermeture1);
        }

        @Override
        public void exec() {
            if (pPredicat1.eval() == true) {
                pFermeture1.exec();
            } else {
                pFermeture2.exec();
            }
        }
    }
}










